package com.qf.j2102.controller;

import com.qf.j2102.po.Dept;
import com.qf.j2102.service.DeptService;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

@Controller
public class DeptController {
    @Autowired
    private DeptService deptService;
    @RequestMapping("/depts")
    public String list(Model model){
        List<Dept> listall = deptService.listall();
        model.addAttribute("depes",listall);
        return "list";
    }
    @RequestMapping(value = "/listone/{id}",method = RequestMethod.GET)
    public String listone(@PathVariable("id") int id, Model model){
        Dept listone = deptService.listone(id);
        model.addAttribute("dept",listone);
        return "update";
    }
    @RequestMapping(value = "/update" ,method = RequestMethod.POST)
    public String update(Dept dept){
        boolean update = deptService.update(dept);
        return "redirect:/depts";
    }

}
